///////////////////////////////////////////////////////////////////////////
// Copyright 2009 Arabic Game Developer Network  All rights reserved
// www.agd-online.com - info@agdn-online.com
//
// File: core2.h
// Description: Core library header for low-level game services.
//
///////////////////////////////////////////////////////////////////////////

// This file is part of kvalleyX.
// 
// kvalleyX is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// kvalleyX is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with kvalleyX.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _CORE2_H
#define _CORE2_H

/////////////////// #defines //////////////////////////////////////////////
#define MAX_AUDIO_SLOTS 20

#ifdef WINDOWS
#define CORELIB_API __declspec(dllexport)
#else
#define CORELIB_API
#endif

#include <boost/cstdint.hpp>
#include <boost/scoped_ptr.hpp>
#include "eventmanager.h"
#include "baseapp.h"

// Forward Reference
class SpriteArt;

namespace CoreLib
{
	struct RECTANGLE
	{
		int top;
		int left;
		int right;
		int bottom;
	};
	typedef RECTANGLE RECT;

	class Core2
	{
		///TODO: Add the rest of the global functions to this class
		///TODO: Review how to export classes in DLLs
		///TODO: Review hot to allow C linking witht his library
		protected:
			Core2();
		public:
			static Core2& getInstance();
			// Init the library. Call it once at application start, with the
			// required settings.
			bool init(BaseApp& app, unsigned int screenWidth,
				 unsigned int screenHeight, bool fullScreen);
			// Run the application at the specified speed (inframes-per-second).
			void run(int fps);
			// Shutdown the library. Call it at application exit to free
			// resources.
			void shutdown(void);

			EventManager& getEventManager() const;
			InputManager& getInputManager() const;
	};
	
	// Init the library. Call it once at application start, with the required
	// settings.
// CORELIB_API bool LibInit(BaseApp *pApp, unsigned int screenWidth, 
// 						 unsigned int screenHeight, bool fullScreen);

// Shutdown the library. Call it at application exit to free resources.
// CORELIB_API void LibShutdown(void);

// Run the application at the specified speed (in frames-per-second).
// CORELIB_API void LibRun(int iFPS);

// Switch between full-screen and windowed mode.
CORELIB_API void LibSwitchFullScreen(void);

// Audio handling. Effects are loaded into slots (IDs)
CORELIB_API bool AudioLoad(int iSlot,const char *pszWavFileName);
CORELIB_API void AudioPlay(int iSlot);
CORELIB_API void AudioStop(int iSlot);
CORELIB_API void AudioRewind(int iSlot);
CORELIB_API bool AudioIsPlaying(int iSlot);

// 2D drawing block. Must be called when drawing 2D fonts and sprites only (not splashes)
CORELIB_API void Begin2D(void);
CORELIB_API void End2D(void);

// Font management.
CORELIB_API bool FontLoad(const char *pszFontFile);
CORELIB_API void FontPutChar(int iScreenX,int iScreenY,const RECT& rcSource);

// Sprite management.
CORELIB_API bool SpriteArtLoad(const char *pszArtName,SpriteArt *pArt);
CORELIB_API void SpriteArtUnload(SpriteArt *pArt);
//CORELIB_API void SpriteDraw(const SpriteArt *pArt,int iX,int iY,const RECT& rcSrc,bool bFlip,DWORD clrTint, bool bBR);

// Splash (backgrounds) management.
CORELIB_API void* SplashLoad(const char *pszArtName);
CORELIB_API void SplashUnload(void *pSplash);
CORELIB_API void SplashDraw(void *pSplash,int iX,int iY);
CORELIB_API void SplashFill(unsigned int clrVal, int top=-1, int left=-1, int bottom=-1, int right=-1);

// Chamber handling (drawing and changing).
CORELIB_API unsigned short* ChamberGetCell(void* pRefTexMap,int iX,int iY);
CORELIB_API void ChamberDrawBricks(void* pRefBlock,void* pRefTexMap,int Chamber_width,int Chamber_height,int Chamber_cell,int Chamber_top,int Chamber_left,int Chamber_bottom,int Chamber_right,int ChamberScrollX);
CORELIB_API void ChamberChanged(void* pRefTexMap);
CORELIB_API void ChamberClipBegin(uint32_t wLeft, uint32_t wRight);
CORELIB_API void ChamberClipEnd(void);
CORELIB_API void ChamberUnload(void* pRefTexMap);

// Chamber blocks management.
CORELIB_API void* BlockArtLoad(const char *pszArtName,char szOutCrushName[64]);
CORELIB_API void BlockArtUnload(void *pArt);
} // CoreLib Namespace

#endif // _CORE2_H

////////////////// End of File : CoreLib.h ////////////////////////////////
